<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/sys/menu/";  //应用的地址名
String viewAreaName = request.getParameter("viewAreaName");  //菜单查看区域的id名称
String treeName = request.getParameter("treeName");  //菜单树的名称
String menuId = com.ce.framework.util.GeneratorUUID.generateUUID(); //菜单id
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>菜单表添加</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/jquery-easyui-1.2/themes/default/datagrid.css"><!-- easyui默认样式 -->

<script type="text/javascript">
<!--
           $(function(){
               //初始化工作，因为远程载入该界面时无法通过在标签中进行设置相应的验证属性等信息，必须要在这里进行初始化
              // $('#add').linkbutton();
               //$('#save').linkbutton();
               $('#vcName').validatebox({
                   required:'true',
                   missingMessage:'必须输入菜单名称',
                   validType:['length[1,25]','specialChar']
               });
	           $('#intSeq').validatebox({
	              required:'true',
	              missingMessage:'必须输入数字排序号',
	              validType:'intNumber[0,9999]'
	           });
               //url
               $('#vcUrl').validatebox({
                   validType:'length[1,150]&specialHtmlChar'
               });
               //菜单描述
               $('#vcMemo').validatebox({
                   validType:'length[1,1000]'
               });
	           //点击添加按钮操作
			   $('#addBtn').click(function(){
                  $('#addForm').submit();
	            });
			   $('#add').click(function(){
                  addRow();
	            });
			   $('#menuLib').change(function(){
				   var val = $('#menuLib').val();
        		   var name = ''+$('#menuLib option[value="'+val+'"]').text();
        		   name = name.indexOf('/')>0?name.substring(name.lastIndexOf('/')+1):name;
				   $('#vcName').val(name);
				   $('#vcUrl').val(val);
				   $.getJSON('<%=path%>/sys/menu/SysMenu.action',{op:'loadMenu',url:val},function(json){
					   $('#rowBody').empty();
					   for(var i=0;i<json.length;i++){
						   addRow(json[i]);
					   }
				   });
			   });
			   
	            //表单验证及提交处理操作
	           $('#addForm').form({
			        url:'<%=basePath%>SysMenu_add.action?menuid=<%=menuId%>&op=savejs',
			        onSubmit: function(){
			            //初始化验证控件
			            var name = $("input[id='name']");
			        	for(var i=0;i<name.length;i++){
			        	   $(name[i]).validatebox({required:'true',missingMessage:'必须输入操作名称',validType:'length[1,15]&specialChar'});
						 }	
						 
                        var simpleName = $("input[id='simpleName']");
			        	for(var i=0;i<simpleName.length;i++){
			        	   $(simpleName[i]).validatebox({required:'true',missingMessage:'必须输入操作简写',validType:'length[1,20]&specialChar'});
						 }
						 
			            var nseq = $("input[id='nseq']");
			        	for(var i=0;i<nseq.length;i++){
			        	   $(nseq[i]).validatebox({required:'true',missingMessage:'必须输入数字排序号',validType:'intNumber[0,9999]'});
						 }	
						
						//函数名称 
						var funname = $("input[id='funname']");
						for(var i=0;i<nseq.length;i++){
			        	   $(funname[i]).validatebox({validType:'length[1,25]&specialChar'});
						 }
						//按钮名称
						var idname = $("input[id='idname']");
						for(var i=0;i<nseq.length;i++){
			        	   $(idname[i]).validatebox({validType:'length[1,15]&specialChar'});
						 } 
						//按钮图标 
						var ico = $("input[id='ico']");
						for(var i=0;i<nseq.length;i++){
			        	   $(ico[i]).validatebox({validType:'length[1,25]&specialChar'});
						 }  
						
			            if($(this).form('validate')){
			                 $.util.showLoading();
			                 $('#operateWindow').window('close');
                            return true;
			             }else{
			                return false;
			             }
			        },			        
			        success:function(data){
			            $.util.removeLoading();
			            try{
				            jsonReStr = jQuery.parseJSON(data);  //获取从服务器得到的数据反馈信息
				            if(jsonReStr.opState=="success"){    //操作成功处理
					            $.util.showTip({content:'数据添加成功！'});
					            //在树上增加节点
					            var node = $('#<%=treeName%>').tree('getSelected');
								$('#<%=treeName%>').tree('append',{
									parent: (node?node.target:null),
									data:[{
										text:$('#vcName').val(),
										id:$('#vcId').val()
									}]
								});
				            }else if(jsonReStr.opState=="failure"){  //操作失败处理
				                $.messager.alert('消息提示','操作处理失败！原因如下：<br><font color=red>'+jsonReStr.opInfo+'</font>','error');
				            }
			            }catch(e){
			               $.messager.alert('消息提示','出现系统错误!可能原因如下：<br><font color=red>'+e+'</font>','error');
			            }
			        }
				});
	            
           });
		var showIcons = function() {
			var dialog = parent.sy.modalDialog({
				title : '浏览小图标',
				url : '<%=path%>/extIcon/icons.jsp',
				buttons : [ {
					text : '确定',
					handler : function() {
						dialog.find('iframe').get(0).contentWindow.selectIcon(dialog, $('#vcIconCls'));
					}
				} ]
			});
		};
           //删除行
           function delRow(obj){
               $(obj).parent().parent().remove();                 
           }
           //添加行
           function addRow(rd){
        	   rd = rd||{};
        	   function val(name){return rd&&(rd[name]||rd[name]==0)?rd[name]:'';}
              var row = '        <tr id="dataRow">'+
            '<td><INPUT type="text" id="nseq" name="opts.nseq" style="width:100%" value="'+val('opSeq')+'"/></td>'+
            '<td><INPUT type="text" id="name" name="opts.vcName" value="'+val('opName')+'" style="width:100%"/></td>'+
            '<td><INPUT type="text" id="simpleName" name="opts.vcSimpleName" value="'+val('opSname')+'" style="width:100%"/></td>'+
            '<td><INPUT type="text" id="funname" name="opts.vcFunname" value="'+val('opFname')+'" style="width:100%"/></td>'+
            '<td><INPUT type="text" id="idname" name="opts.vcIdname" value="'+val('opBname')+'" style="width:100%"/></td>'+
            '<td><INPUT type="text" id="ico" name="opts.vcIco" value="'+val('opIcon')+'" style="width:100%"/></td>'+
            '<td align="center"><input type="checkbox" onclick="delRow(this)"/></td>'+
            '<INPUT type="hidden" id="vcid" name="opts.vcId"/>'+
            '<INPUT type="hidden" name="opts.vcDelFlag" value="0"/>'+
            '<INPUT type="hidden" name="opts.vcMenuId" value="<%=menuId %>"/>'+
            '</tr>';
            $('#rowBody').append(row);
           }
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<form id="addForm" method="post">
<table align="center" width="100%"  class="tb_add_th">
<input type="hidden" id="vcId" name="po.vcId" value="<%=menuId %>">
<input type="hidden" id="vcParId" name="po.vcParId" value="<s:property value='#parameters.pid'/>">
<input type="hidden" id="intLevel" name="po.intLevel" value=0>
<input type="hidden" id="vcLinkUrl" name="po.vcLinkUrl">
<input type="hidden" id="vcDelFlag" name="po.vcDelFlag" value="0">

<tr><th width="150" align="left">菜单库:</th><td><s:select id="menuLib" list="#request.menuLib" listKey="vcId" listValue="vcName" headerKey="" headerValue="--请从菜单库中选择--"/></td></tr>
<tr><th width="150" align="left">菜单名称:</th><td><input type="text" id="vcName" name="po.vcName" style="width:200px"><font color="red">*</font></td></tr>
<tr><th align="left">菜单URL:</th><td><input type="text" id="vcUrl" name="po.vcUrl" style="width:200px"></td></tr>
<tr><th align="left">菜单图标:</th><td><input type="text" id="vcIconCls" name="po.vcIconCls" readonly="readonly" style="padding-left: 18px; width: 200px;" /><img class="iconImg ext-icon-zoom" onclick="showIcons();" title="浏览图标" />&nbsp;<img class="iconImg ext-icon-cross" onclick="$('#iconCls').val('');$('#iconCls').attr('class','');" title="清空" /></td></tr>

<tr><th align="left">排序号:</th><td><input type="text" id="intSeq" name="po.intSeq" style="width:200px" value="<s:property value='#request.nseq'/>"><font color="red">*</font></td></tr>
<tr><th align="left">是否为子系统:</th><td><select id="vcIsMerge" name="po.vcIsMerge" style="width:200px"><option value="0">否</option><option value="1">是</option></select></td></tr>
	<tr><th>参数配置:</th><td><s:textarea id="vcMemo"  name="po.vcMemo" label="菜单描述" style="width:99%;height:60px;"></s:textarea></td></tr>
</table>
<table id="dataList"  class="tb_list_gen" style="width:600px;height:auto;" align="center">
   <caption>选择菜单操作功能</caption>
    <thead>
        <tr>
            <th width="40">排序</th>
            <th width="80" norowp="true">操作名称</th>
            <th width="80">操作简写</th>
            <th width="80">函数名称</th>
            <th width="80">按钮名称</th>
            <th width="80">图标</th>
            <th width="50">删除</th>
        </tr>
    </thead>
    <tbody id="rowBody">
    <s:iterator value="#request.defaultOperateList" status="operate">
        <tr>
            <td><INPUT type="text" id="nseq" name="opts.nseq" value="<s:property value="nseq"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="name" name="opts.vcName" value="<s:property value="vcName"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="simpleName" name="opts.vcSimpleName" value="<s:property value="vcSimpleName"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="funname" name="opts.vcFunname" value="<s:property value="vcFunname"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="idname" name="opts.vcIdname" value="<s:property value="vcIdname"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="ico" name="opts.vcIco" value="<s:property value="vcIco"/>" style="width:100%"/></td>
            <td align="center"><input type="checkbox" onClick="delRow(this)"/></td>
            <INPUT type="hidden" id="vcid" name="opts.vcId"/>
            <INPUT type="hidden" id="vcid" name="opts.vcMenuId" value="<%=menuId %>"/>
            <INPUT type="hidden" id="vcid" name="opts.vcDelFlag" value="0"/>
        </tr>
   </s:iterator>    
    </tbody>
</table>
</form>
<!--<div align="right"><a id="add"  href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add">添加新操作</a><a id="addBtn"  href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save">保存</a></div>-->
</body>
</html>


